package com.unipay.task;

import com.google.common.collect.Lists;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;

import java.util.Properties;

/**
 * @Project: Flink17_Jvm
 * @Author: Chenmy
 * @Time: 2023-10-20 10:57:31
 * @Desc: TODO
 */

public class MyConsumer2 {


    public static void main(String[] args) {

        // 消费Kafka配置
        Properties props = new Properties();
        props.put("bootstrap.servers", "172.18.175.132:9092");
        props.setProperty("group.id", "9");
        props.setProperty("enable.auto.commit", "true");
        props.setProperty("auto.offset.reset", "earliest");
        props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");

        Consumer<String, String> consumer = new KafkaConsumer<String, String>(props);
        consumer.subscribe(Lists.newArrayList("gamb_check"));

        for (int i = 0; i < 2; i++) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            System.out.println(records.count());
            for (ConsumerRecord<String, String> record : records) {
                // 打印
                System.out.println(record);

            }
        }
    }


}
